package com.iotimc.attendancesystem.welcome;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.TextView;

import com.iotimc.attendancesystem.R;
import com.iotimc.attendancesystem.base.BaseActivity;
import com.iotimc.comass.util.IotimcSerialHelper;
import com.pefis.natives.Ast2600JNI;
import com.pefis.natives.PfsBioInfo;

import java.io.File;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author david
 * @date 2017/11/27
 */

public class WelcomeActivity extends BaseActivity implements WelcomeContract.View{

    @BindView(R.id.message)
    TextView message;

    @Override
    protected int getResId() {
        return R.layout.activity_welcome;
    }

    WelcomeContract.Presenter presenter;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        presenter = new WelcomePresenter(this,this);
        presenter.initDevice();
    }

    @OnClick(R.id.message)
    public void onViewClicked() {

    }
    @OnClick(R.id.show_check)
    public void onShowCheck(){

    }

    @Override
    public void showLoading() {

    }

    @Override
    public void showMessage(int messageId) {
        message.setText(messageId);
        //DeleteAllUser();
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        presenter.close();
       IotimcSerialHelper.quit();
    }

    private void DeleteAllUser() {
        Ast2600JNI.getInstance().pisFcClearTptArray(
                PfsBioInfo.getInstance().mContextID);

        File mDeleteUserData = new File(PfsBioInfo.TEMPLATE_DB_PATH);
        if (mDeleteUserData.exists()) {
            if (mDeleteUserData.isDirectory()) {
                File[] files = mDeleteUserData.listFiles();
                for (int i = 0; i < files.length; i++) {
                    if (files[i].isFile()) {
                        files[i].delete();
                    }
                }
            }

        }

        mDeleteUserData = new File(PfsBioInfo.PHOTO_DB_PATH);
        if (mDeleteUserData.exists()) {
            File[] files = mDeleteUserData.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isFile()) {
                    files[i].delete();
                }
            }
        }
    }
}
